<!-- 搜索表单 -->
<template>
  <div class="searchContainer">
    <el-card
      class="box-card"
      body-style="padding: 22px 22px 0 22px;"
      shadow="never"
    >
      <el-form
        label-width="77px"
        class="ele-form-search"
        @keyup.enter.native="search"
        @submit.native.prevent
        ref="where"
        :model="where"
      >
        <el-row :gutter="15">
          <el-col v-bind="styleResponsive ? { lg: 8, md: 12 } : { span: 8 }">
            <el-form-item label="商品名称:" prop="tradeName">
              <el-input
                clearable
                v-model="where.tradeName"
                placeholder="请输入商品名称"
              />
            </el-form-item>
          </el-col>

          <el-col v-bind="styleResponsive ? { lg: 8, md: 12 } : { span: 8 }">
            <el-form-item label="商品状态:" prop="notGrounding">
              <el-select
                clearable
                class="ele-block"
                v-model="where.notGrounding"
                placeholder="请选择商品上下架状态"
              >
                <el-option
                  v-for="(i, j) in productStatusList"
                  :key="j"
                  :label="i.label"
                  :value="i.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col v-bind="styleResponsive ? { lg: 8, md: 12 } : { span: 8 }">
            <el-form-item label="创建时间:" prop="dateRange">
              <el-date-picker
                v-model="where.dateRange"
                type="datetimerange"
                unlink-panels
                range-separator="至"
                :default-time="['00:00:00', '23:59:59']"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
                value-format="yyyy-MM-ddTHH:mm:ss"
                class="ele-fluid"
              />
            </el-form-item>
          </el-col>
          <el-col v-bind="styleResponsive ? { lg: 8, md: 12 } : { span: 8 }">
            <div class="ele-form-actions">
              <el-button
                type="primary"
                icon="el-icon-search"
                class="ele-btn-icon"
                @click="search"
              >
                查询
              </el-button>
              <el-button @click="resetForm('where')">重置</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
  </div>
</template>
<script>
  import { getRegionLabel } from 'ele-admin/packages/utils/regions';
  import { productStatusList } from '../constant/constant';
  export default {
    name: 'SystemUser',
    components: {},
    data() {
      // 默认表单数据
      const defaultWhere = {
        // 商品名称
        tradeName: '',
        // 商品上下架
        notGrounding: '',
        // 申请时间
        dateRange: []
      };
      return {
        productStatusList,
        // 表单数据
        where: {
          ...defaultWhere
        },
        sumbitForm: {}
      };
    },
    props: {
      typeList: Array,
      oemList: {
        type: Array,
        default: () => []
      },
      secondaryList: {
        type: Array,
        default: () => []
      },
      currentPlatform: {
        type: String,
        default: ''
      }
    },
    computed: {
      // 是否开启响应式布局
      styleResponsive() {
        return this.$store.state.theme.styleResponsive;
      }
    },
    methods: {
      /* 搜索 */
      search() {
        for (const key in this.where) {
          if (key == 'dateRange') {
            let startTime = this.where[key]?.[0];
            let endTime = this.where[key]?.[1];
            this.sumbitForm['createTimeStart'] =
              startTime == undefined ? '' : startTime;
            this.sumbitForm['createTimeEnd'] =
              endTime == undefined ? '' : endTime;
          } else if (key == 'orderAmount') {
            this.sumbitForm['startOrderAmount'] =
              this.where[key].startOrderAmount == undefined
                ? ''
                : this.where[key].startOrderAmount;
            this.sumbitForm['endOrderAmount'] =
              this.where[key].endOrderAmount == undefined
                ? ''
                : this.where[key].endOrderAmount;
          } else {
            this.sumbitForm[key] = this.where[key] ? this.where[key] : '';
          }
        }
        console.log(this.sumbitForm);
        this.$emit('search', this.sumbitForm);
      },
      /*  重置 */
      resetForm(formName) {
        this.$refs[formName].resetFields();

        this.where = {};
        this.sumbitForm = {};
        this.$emit('search', this.sumbitForm);
      }
    }
  };
</script>
<style lang="less" scoped>
  .searchContainer {
    padding-bottom: 15px;
  }
  /deep/ .el-form-item__label {
    text-align: inherit;
  }
  .navList {
    margin-bottom: 25px;
    font-weight: 700;
  }
</style>
